package com.fyyg.common.util;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;

public class StrUtil {
	/**
	 * 禁止实例化
	 */
	public static SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static SimpleDateFormat f1 = new SimpleDateFormat("yyyy-MM-dd");
	public static SimpleDateFormat f2 = new SimpleDateFormat("yyyy-MM ");
	private StrUtil() {
	}
	
	/**
	 * 判断字符串是否为空
	 * @param str 要判断的字符串
	 * @return 为空返回true 反之返回false
	 */
	public static boolean isEmpty(String str){
		if (null==str||str.trim().length()==0) {
			return true;
		}else {
			return false;
		}
	}
	
	/**
	 * 判断对象是否是null或者空字符串
	 * @param str
	 * @return 是true，否false
	 */
	public static boolean isBlank(Object str)
	{
		if(str==null||str.toString().trim().length()==0)
		{
			return true;
		}
		else {
			return false;
		}
	}
	
	/**
	 * 分割并且去除空格
	 * 
	 * @param str
	 *            待分割字符串
	 * @param sep
	 *            分割符
	 * @param sep2
	 *            第二个分隔符
	 * @return 如果str为空，则返回null。
	 */
	public static String[] splitAndTrim(String str, String sep, String sep2) {
		if (StringUtils.isBlank(str)) {
			return null;
		}
		if (!StringUtils.isBlank(sep2)) {
			str = StringUtils.replace(str, sep2, sep);
		}
		String[] arr = StringUtils.split(str, sep);
		// trim
		for (int i = 0, len = arr.length; i < len; i++) {
			arr[i] = arr[i].trim();
		}
		return arr;
	}


	/**
	 * 截断字符串，在截断的字符串后加上后缀，如"..."
	 * 
	 * @param s
	 *            剪切对象。
	 * @param len
	 *            编码小于256的作为一个字符，大于256的作为两个字符。
	 * @param append 截断后追加的后缀，比如 ...
	 * @return
	 */
	public static String subStr(String s, int len, String append) {
		if (s == null) {
			return null;
		}
		int slen = s.length();
		if (slen <= len) {
			return s;
		}
		s=s.substring(0,len);
		s=s+append;
		return s;
	}
	/*public static String subStr(String s, int len, String append) {
		if (s == null) {
			return null;
		}
		int slen = s.length();
		if (slen <= len) {
			return s;
		}
		// 最大计数（如果全是英文）
		int maxCount = len * 2;
		int count = 0;
		int i = 0;
		for (; count < maxCount && i < slen; i++) {
			if (s.codePointAt(i) < 256) {
				count++;
			} else {
				count += 2;
			}
		}
		if (i < slen) {
			if (count > maxCount) {
				i--;
			}
			if (!StringUtils.isBlank(append)) {
				if (s.codePointAt(i - 1) < 256) {
					i -= 2;
				} else {
					i--;
				}
				return s.substring(0, i) + append;
			} else {
				return s.substring(0, i);
			}
		} else {
			return s;
		}
	}
*/

	/**
	 * 检查字符串中是否包含被搜索的字符串。被搜索的字符串可以使用通配符'*'。
	 * 
	 * @param str
	 * @param search
	 * @return
	 */
	public static boolean contains(String str, String search) {
		if (StringUtils.isBlank(str) || StringUtils.isBlank(search)) {
			return false;
		}
		String reg = StringUtils.replace(search, "*", ".*");
		Pattern p = Pattern.compile(reg);
		return p.matcher(str).matches();
	}
	
	/**
	 * 
	* @Description: 
	* @param reg 正则表达式
	* @param str 需要处理的字符串
	* @param replaceStr 要替换的字符串
	* @return String
	* @throws
	 */
	public static String regxpMatch(String reg,String str,String replaceStr){
		if(str == null){
			return "";
		}else if(reg == null || "".equals(reg)){
			return str;
		}else{
			String s = "";
			s = str.replaceAll(reg,replaceStr);
			return s;
		}
	}
	
	/**
	 * 
	* @Description: 
	* 正则表达式替换字符串html标签
	* @param str
	* @return String
	* @throws
	 */
	public static String regxpHtml(String str){
		if(str == null){
			return "";
		}else{
			//String htmlRAngleReg = "<[^>]*>";
			//String htmlLAngleReg = "[(/>)<]";
			//String htmlTagReg = "\\&[a-zA-Z]{1,10};";
			//String htmlRapReg ="\\s";
			//String htmlEnter ="\t|\r|\n";
			//str = str.replaceAll(htmlRAngleReg,"");
			//str = str.replaceAll(htmlLAngleReg,"");
			//str = str.replaceAll(htmlTagReg,"");
			//str = str.replace(htmlRapReg, "");
			//str = str.replace(htmlEnter,"");
			//str = str.trim();
			str = str.replaceAll("\\<.*?>|\\s|&nbsp;", "");
			str=StringEscapeUtils.unescapeHtml(str);
			return str;
		}
	}
	
	/**
	 * 防止alert()弹出
	 * @param str
	 * @return
	 */
	public static String replaceSign(String str){
		if(str==null || "".equals(str)){
			return str;
		}else{
			str = str.replace("<","&lt;");
			str = str.replace(">","&gt;");
			str = str.replace("/","&frasl;");
			return str;
		}
	}
	
	/*public static void main(String[] args) {
		//String value="abc中国，，";
		//System.out.println(getRealLength(value));
	    String scope = "(9000009001, 9000010000)";
	    String value = "9000010000";
	    Boolean result = StrUtil.isInScope(scope, value);
	    System.out.println(result);
	    String str1=" 90000  13999900    000601590   00092073";
	    String str = "900001399990000060159000092073";
	    System.out.println(StrUtil.strWaybillNo(str1));
	}*/
	
	public static List strWaybillNo(String str){
	    str = str.replaceAll(" ", "").replaceAll("\r|\n", "");
	    List<String> waybillLlist = null;
	    if(str != null){
		waybillLlist = new ArrayList<String>();
		for(int i=0;i<str.length()/10;i++){
		    waybillLlist.add(str.substring(i*10, (i+1)*10));
		}
	    }
	    return waybillLlist;
	}
	
	public static List strReceiptNo(String str){
	    str = str.replaceAll(" ", "");
	    List<String> receiptNolist = null;
	    if(str != null){
	    	receiptNolist = new ArrayList<String>();
		for(int i=0;i<str.length()/8;i++){
			receiptNolist.add(str.substring(i*8, (i+1)*8));
		}
	    }
	    return receiptNolist;
	}
	
	/**
	 * 取得字符窜长度，数字按1文字按2
	 * @param str
	 * @return
	 */
	public static int getRealLength(String str){
		int length=0;
		for (int i = 0; i < str.length(); i++) {
			String tempStr=String.valueOf(str.charAt(i));
			if (tempStr.getBytes().length>1) {
				length=length+2;
			}else {
				length=length+1;
			}
		}
		return length;
		
	}

	/**
	 * 截取字符串
	 * @param memString
	 * @param maxsize
	 * @param needsize
	 * @param suffix
	 * @return
	 */
	public static String getSubString(String memString,int maxsize,int needsize,String suffix){
		if (memString!=null) {
			if (getRealLength(memString)<=maxsize) {
				return memString;
			}else {
				int memCount=0;
				int i = 0;
				for (;i < memString.length(); i++) {
					if (String.valueOf(memString.charAt(i)).getBytes().length>1) {
						memCount=memCount+2;
					}else {
						memCount=memCount+1;
					}
					if (memCount>needsize) {
						break;
					}else if (memCount==needsize) {
						i=i+1;
						break;
					}else {
					}
				}
				return memString.substring(0,i)+suffix;
			}
		}else {
			return null;
		}
	}
	
	/**
	 * 转码
	 * @param str
	 * @return
	 */
	public static String convertUTF82(String str) {
		try {
			if(!"".equals(str) && str !=null){
				System.out.println("before convert encode:--->>" + str);
				byte[] iso = str.getBytes("ISO-8859-1");
				String st1 = new String(iso, "UTF-8");
				//如果包含汉字
				if(StrUtil.extractChina(st1).length()>0){
					str = st1;
				}else{
					str = URLDecoder.decode(str, "UTF-8");
				}
				System.out.println("after convert encode:--->>" + str);
				return str;
			}
			return "";
		} catch (UnsupportedEncodingException e) {
			System.out.println("---------------String convert exception");
			e.printStackTrace();
			return "";
		}
	}
	
	/**
	 * 抽出一个字符串的中文
	 * @param str
	 * @return
	 */
	public static String extractChina(String str){
		String regEx = "[\\u4e00-\\u9fa5]";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(str);
		System.out.print("the Chinese words by extract is:--->>");
		String result = "";
		while (m.find()) {
			System.out.print(m.group(0) + " ");
			result += m.group(0);
		}
		System.out.println();
		return result;
	}
	
	/**
	 * 将字符串转为int[]
	 * @param str 1,2,3,4 此参数一定需是逗号隔开
	 * @return
	 */
	public static Integer[] StringtoInt(String str) {  
		String [] idString = str.split(",");
	 	Integer ret[] = new Integer[idString.length];   
	    StringTokenizer toKenizer = new StringTokenizer(str, ",");   
	    int i = 0;  
	    while (toKenizer.hasMoreElements()) {   
	      ret[i++] = Integer.valueOf(toKenizer.nextToken());  
	    }   
	    return ret;  
	} 
	
 /**
  * 判断是否为空
  * @return
  */	
 public static boolean isNotEmpty(String str){
	 if(str !=null && !"".equals(str)){
		 return true;
	 }
	 return false;
 }
 
 public static Timestamp getCurrentTimestampt(){	
		return new Timestamp(new Date().getTime());
	}
//获取当前时间 时分秒
 public static String getNowDate(){
   return f.format(new Date());
 }
 
//获取当前时间 不带 时分秒
 public static String getNowDate1(){
   return f1.format(new Date());
 }

//获取每月的第一天 yyyy-MM-dd HH:mm:ss
 public static String getFirstDate(){
    Calendar c = Calendar.getInstance();    
    c.add(Calendar.MONTH, 0);
    c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
    return f.format(c.getTime());
 }
 
 public static String getMonthFirstDay(){
     Calendar c = Calendar.getInstance();    
     c.add(Calendar.MONTH, 0);
     c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
     return f1.format(c.getTime());
  }

 //获取上个月第一天 
 public static String getPrieDate(){
	    Calendar c = Calendar.getInstance();    
	    c.add(Calendar.MONTH, -1);
	    c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
	    return f1.format(c.getTime());
 }
 
 //获取上个月 YYYY-M
 public static String getprieMonth(){
	 Calendar c = Calendar.getInstance();    
	    c.add(Calendar.MONTH, -1);
	    return f2.format(c.getTime());
 }
 
//获取上个月最后一天 
 public static String getPrieLastDate(){
	    Calendar c = Calendar.getInstance();    
	    c.set(Calendar.DAY_OF_MONTH, 1); 
	    c.add(Calendar.DATE, -1); //先将日期设置为本月的第一天，然后减去一天就变成了上个月的最后一天了
	    return f1.format(c.getTime());
 }
 
//获取当前月第一天 
 public static String getNowMonthPrieDate(){
	    Calendar c = Calendar.getInstance();    
	    //c.add(Calendar.MONTH, -1);
	    c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
	    return f1.format(c.getTime());
 }
 
//获取当前月的最后一天
 public static String getNowMonthLastDay(){
     Calendar cal = GregorianCalendar.getInstance();
     cal.add(Calendar.MONTH, 1);
     cal.set(Calendar.DAY_OF_MONTH,1);
     cal.add(Calendar.DATE, -1);
     return f1.format(cal.getTime());
 }
 
 //获取当前日期前一天数据
 public static String getFirstDay(){
	 Calendar   cal   =   Calendar.getInstance();
	 cal.add(Calendar.DATE,   -1);
     return f1.format(cal.getTime());
 }
 
//获取当前日期前两天数据
 public static String getTwoDay(){
	 Calendar   cal   =   Calendar.getInstance();
	 cal.add(Calendar.HOUR,   -48);
     return f.format(cal.getTime());
 }
 
//获取当前日期前一个月数据
 public static String getOneMonth(){
	 Calendar   cal   =   Calendar.getInstance();
	 cal.add(Calendar.HOUR,   -720);
     return f.format(cal.getTime());
 }
 
//获取某个日期前两天数据
 public static String getOtherTwoDay(String time){
	 Calendar cal = Calendar.getInstance();
	 try {
		cal.setTime(f.parse(time));
	} catch (ParseException e) {
		e.printStackTrace();
	}
	cal.add(Calendar.HOUR,   -48);
    return f.format(cal.getTime());
 }
 
//获取某个日期下一个月第一天
 public static String getNextMonthFirstDay(String time){
	 Calendar cal = Calendar.getInstance();
	 try {
		cal.setTime(f1.parse(time));
	} catch (ParseException e) {
		e.printStackTrace();
	}
	cal.add(Calendar.MONTH, 1);
    cal.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天 
    return f1.format(cal.getTime());
 }

/** 
 * 将String型格式化,比如想要将2011-11-11格式化成2011年11月11日,就StringPattern("2011-11-11","yyyy-MM-dd","yyyy年MM月dd日").
 * @param date String 想要格式化的日期
 * @param oldPattern String 想要格式化的日期的现有格式
 * @param newPattern String 想要格式化成什么格式
 * @return String 
 */ 
public static String StringPattern(String date, String oldPattern, String newPattern) { 
    if (date == null || oldPattern == null || newPattern == null) 
        return ""; 
    SimpleDateFormat sdf1 = new SimpleDateFormat(oldPattern) ;        // 实例化模板对象  
    SimpleDateFormat sdf2 = new SimpleDateFormat(newPattern) ;        // 实例化模板对象  
    Date d = null ;  
    try{  
        d = sdf1.parse(date) ;   // 将给定的字符串中的日期提取出来  
    }catch(Exception e){            // 如果提供的字符串格式有错误，则进行异常处理  
        e.printStackTrace() ;       // 打印异常信息  
    }  
    return sdf2.format(d);
} 

/**
 * 日期比较  是否属于当天的日期
 * @@param date
 */
 public static String dateComparison(String firstDate,String senconDate,String orderAging){
	 try {
		    String result="";
		    Date d1 = f.parse(senconDate);
			String dStr=StringPattern(firstDate,"yyyy-MM-dd HH:mm:ss","yyyy-MM-dd");
			Date d2=f.parse(dStr+" 23:59:59");
			long diff =(d2.getTime() - d1.getTime())/1000;
			if(diff>=0){
				result="";
			}else{
				if(isNotEmpty(orderAging)){
					String symbol=orderAging.substring(1,2);
					if("-".equals(symbol)){
						String  days=orderAging.split("-")[1];
						int d=Integer.parseInt(days)-1;
						result="D-"+d;
					}
					if("+".equals(symbol)){
						String  days=orderAging.split("\\+")[1];
						int d=Integer.parseInt(days)+1;
						result="D+"+d;
					}
				}else{
					result="";
				}
			}
		return result;
	} catch (ParseException e) {
		e.printStackTrace();
	}
	return "";
 }
 
 /**
  * 日期比较  是否属于当天的日期 不显示时效
  * @@param date
  */
  public static String dateComparison1(String firstDate,String senconDate){
 	 try {
 		    String result="";
 		    Date d1 = f.parse(senconDate);
 			String dStr=StringPattern(firstDate,"yyyy-MM-dd HH:mm:ss","yyyy-MM-dd");
 			Date d2=f.parse(dStr+" 23:59:59");
 			long diff =(d2.getTime() - d1.getTime())/1000;
 			if(diff>=0){
 				result="";
 			}else{
 			   result=StringPattern(senconDate,"yyyy-MM-dd HH:mm:ss","yyyy-MM-dd");;
 			}
 		return result;
 	} catch (ParseException e) {
 		e.printStackTrace();
 	}
 	return "";
  }
  
  /**
   * 返回时间
   * @return
   */
  public static String printTimeStamp() {
		Calendar ca = Calendar.getInstance();
		ca.setTimeInMillis(System.currentTimeMillis());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS ",
				Locale.CHINA);
		// 显示当前时间 精确到毫秒
		return sdf.format(ca.getTime());
	}
  
  /**
   * 两日期相减 秒
   * @param date1
   * @param date2
   * @return
   */
  public static long dateSub(String date1,String date2){
	  try {  
		  // 这个的除以1000得到秒，相应的60000得到分，3600000得到小时  
          long result = (f.parse(date2).getTime() - f.parse(date1).getTime()) / 1000; 
          return result;
      } catch (ParseException e) {  
          e.printStackTrace();  
          return 0;
      }  
	  
  }
  
  
  
  /**
   * 两日期相减  分
   * @param date1
   * @param date2
   * @return
   */
  public static long dateSub1(String date1,String date2){
	  try {  
		  // 这个的除以1000得到秒，相应的60000得到分，3600000得到小时  
          long result = (f.parse(date2).getTime() - f.parse(date1).getTime()) / 60000; 
          return result;
      } catch (ParseException e) {  
          e.printStackTrace();  
          return 0;
      }  
	  
  }
  
  
  
  
  public static boolean isInScope(String scope, String value) {
      Pattern pattern = Pattern.compile("^(\\(|\\[)\\d+,\\s*\\d+(\\)|\\])$");
      Matcher matcher = pattern.matcher(scope);
      if (!matcher.find()) {
	  return false;
      }
      
      String[] scopes = scope.split(",");
      BigDecimal valueF = new BigDecimal(value);
      //Double valueF = Double.valueOf(value);
      BigDecimal min = new BigDecimal(scopes[0].substring(1));

      if ("(".equals(String.valueOf(scopes[0].charAt(0)))) {
	  if (valueF.compareTo(min) == -1){
	      return false;
	  }
      } else if ("[".equals(String.valueOf(scopes[0].charAt(0)))) {
	  if (valueF.compareTo(min) == -1)
	      return false;
      }

      System.out.println(scopes[1].substring(0, scopes[1].length() - 1).replace(" ", ""));
      BigDecimal max = new BigDecimal(scopes[1].substring(0, scopes[1].length() - 1).replace(" ", ""));
      if (")".equals(String.valueOf(scopes[1].charAt(scopes[1].length() - 1)))) {
	  if (valueF.compareTo(max) == 1)
	      return false;
      } else if ("]".equals(String.valueOf(scopes[1].charAt(scopes[1].length() - 1)))) {
	  if (valueF.compareTo(max) == 1)
	      return false;
      }

      return true;
  }
  
  /** 
  * 在数字型字符串千分位加逗号 
  * @param str 
  * @return 
  */  
  public static String addComma(String str){  
      boolean neg = false;  
      if (str.startsWith("-")){  //处理负数  
          str = str.substring(1);  
          neg = true;  
      }  
      String tail = null;  
      if (str.indexOf('.') != -1){ //处理小数点  
          tail = str.substring(str.indexOf('.'));  
          str = str.substring(0, str.indexOf('.'));  
      }  
      StringBuilder sb = new StringBuilder(str);  
      sb.reverse();  
      for (int i = 3; i < sb.length(); i += 4){  
          sb.insert(i, ',');  
      }  
      sb.reverse();  
      if (neg){  
          sb.insert(0, '-');  
      }  
      if (tail != null){  
          sb.append(tail);  
      }  
      return sb.toString();  
  }
  
  //判断两个日期的大小
  public static Boolean compareDate(String DATE1, String DATE2) {
	DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	Boolean flag = false;
	try {
	    Date dt1 = df.parse(DATE1);
	    Date dt2 = df.parse(DATE2);
	    if (dt1.getTime() > dt2.getTime()) {
		flag = false;
	    } else if (dt1.getTime() < dt2.getTime()) {
		flag = true;
	    } else {
		flag = false;
	    }
	} catch (Exception e) {
	    e.printStackTrace();
	}
	return flag;
  }
  
  //判断DATE3，DATE4是否在DATE1，DATE2区间内
  public static Boolean checkDate(String DATE1, String DATE2, String DATE3, String DATE4){
      Boolean flag = false;
      DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      try{
	  Date date1 = df.parse(DATE1);
	  Date date2 = df.parse(DATE2);
	  Date date3 = df.parse(DATE3);
	  Date date4 = df.parse(DATE4);
	  if(date1.getTime() > date3.getTime()){
	      if(date1.getTime() > date4.getTime()){
		  flag = true;
	      }
	  }
	  if(date1.getTime() <= date3.getTime() && date3.getTime() <= date2.getTime()){
	      flag = false;
	  }
	  if(date2.getTime() < date3.getTime()){
	      flag = true;
	  }
      }catch(Exception e){
	  e.printStackTrace();
      }
      return flag;
  }
  
  public static void main(String[] args) {
      //System.out.println(checkDate("2015-08-15 12:30:12", "2015-08-20 13:26:10", "2015-08-11 12:15:45", "2015-08-16 18:00:00"));
      //checkWaybillNo("9000099001", "9000100000", "9000015001", "9000016000");
      /*String []startWaybillNo = {"9000099001", "9000015001", "9000009001", "9000065001", "9000029001", "9000006001", "9000002001", "9000013001"};
      String []endWaybillNo = {"9000100000", "9000016000", "9000010000", "9000066000", "9000030000", "9000007000", "9000003000", "9000014000"};
      List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
      for(int i=0;i<startWaybillNo.length;i++){
	  Map<String, Object> map = new HashMap<String, Object>();
	  map.put("startWaybillNo", startWaybillNo[i]);
	  map.put("endWaybillNo", endWaybillNo[i]);
	  list.add(map);
      }
      System.out.println(list);
      for(Map<String, Object> map:list){
	  System.out.println(checkWaybillNo(map.get("startWaybillNo").toString(), map.get("endWaybillNo").toString(), "9000015801", "9000016300"));
      }*/
      //String str = "清远三级分拨中心,众辉达广州中心平台,珠海三级分拨中心";
      //System.out.println(serachStr(str));
     //System.out.println(validatePhone("0715-1234567"));
      //getBeforeMonthDay("2015-10-30");
      long aa=dateSub1("2015-11-11 11:10:57","2015-11-11 11:50:20");
      System.out.println("----->"+aa);
      
  }
  
  /**
   * @Description: 
   * @param startWaybillNo1
   * @param endWaybillNo1
   * @param startWaybillNo2
   * @param endWaybillNo2
   * @return Boolean
   */
  public static Boolean checkWaybillNo(String startWaybillNo1, String endWaybillNo1, String startWaybillNo2, String endWaybillNo2){
      Boolean flag = false;
      if(startWaybillNo1.compareTo(startWaybillNo2) > 0){
	  if(startWaybillNo1.compareTo(endWaybillNo2) >= 0){
	      flag = true;
	  }
      }
      if(startWaybillNo1.compareTo(startWaybillNo2) < 0){
	  if(endWaybillNo1.compareTo(startWaybillNo2) < 0){
	      flag = true;
	  }
      }
      return flag;
  }
  
  public static int serachStr(String str){
      String []arrayStr = str.split("\\,");
      Integer count = 0;
      for(String chars:arrayStr){
	  if(chars.indexOf("三级分拨中心") != -1){
	      count++;
	  }
      }
      return count;
  }
  
  public static Boolean validatePhone(String phone){
      Boolean flag = false;
      //String phone= "0715-9548326";
      //System.out.println(phone.replace("-", "").length());
      String newPhone = phone.replace("-", "");
      if(newPhone.length() == 11){
	  //System.out.println("1".equals(newPhone.substring(0, 1)));
	  if("1".equals(newPhone.substring(0, 1))){
	      flag = true;
	  }
      }
      return flag;
  }
  
  //获取当前月的下一个月的最后一天
  public static String getNextMonthLastDay(){
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
      Calendar cal = GregorianCalendar.getInstance();
      cal.set(Calendar.DAY_OF_MONTH, 1);
      cal.set(Calendar.MONTH, GregorianCalendar.getInstance().get(Calendar.MONTH)+2);
      cal.add(Calendar.DATE, -1);
      return format.format(cal.getTime());
  }
  
  //获取指定日期的下一个月的最后一天
  public static String getNextMonthDay(String paramDate) {
      try{
          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
          Date date = format.parse(paramDate);
          Calendar cal = Calendar.getInstance();
          cal.setTime(date);
          cal.set(Calendar.MONTH, cal.get(Calendar.MONTH)+2);
          cal.set(Calendar.DATE, -1);
          String newDate = format.format(cal.getTime()).substring(0,8)+cal.getActualMaximum(Calendar.DAY_OF_MONTH);
          System.out.println(newDate);
          return newDate;
      }catch(Exception e){
	  e.printStackTrace();
      }
      return "";
  }
  
//获取指定日期的 上一个月的最后一天
  public static String getBeforeMonthDay(String paramDate) {
      try{
          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
          Date date = format.parse(paramDate);
          Calendar cal = Calendar.getInstance();
          cal.setTime(date);
          cal.set(Calendar.MONTH, cal.get(Calendar.MONTH));
          cal.set(Calendar.DATE, -1);
          String newDate = format.format(cal.getTime()).substring(0,8)+cal.getActualMaximum(Calendar.DAY_OF_MONTH);
          System.out.println(newDate);
          return newDate;
      }catch(Exception e){
	  e.printStackTrace();
      }
      return "";
  }
	public static String getRandom(){
		  Random rd = new Random();
		  String n="";
		  int getNum;
		  do {
		   getNum = Math.abs(rd.nextInt())%10 + 48;//产生数字0-9的随机数
		   char num1 = (char)getNum;
		   String dn = Character.toString(num1);
		   n += dn;
		  } while (n.length()<6);
		  return n;
}
	
	public static String getLastThreeDay(){
	    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
	    Calendar cal = Calendar.getInstance();
	    //cal.setTime(new Date());
	    cal.add(Calendar.DATE, -3);
	    return format.format(cal.getTime());
	}
	
	
	public static String getLastWeekend(){
	    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
	    Calendar cal = Calendar.getInstance();
	    //cal.setTime(new Date());
	    cal.add(Calendar.DATE, -7);
	    return format.format(cal.getTime());
	}
	
	public static String getUUID(){    
        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");    
        return uuid;    
    }   
	
	 /**
     * 验证手机格式
     * @param mobiles
     * @return
     */
    public static boolean isMobileNO(String mobiles){  
  	  
    	/*Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");  
    	  
    	Matcher m = p.matcher(mobiles);  
    	  
    	return m.matches();*/
		Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");    
	    return pattern.matcher(mobiles).matches(); 
    }
    
}
